import config from "@/config/config.js"
import { styleList, colorList } from "./config"

export default class Theme {
    static key = "theme"
    static getTheme(options){
        const { theme } = config
        const themeData = localStorage.getItem(Theme.key)
        let {styleId, color, isHide} = theme
        if(themeData){
            const data = JSON.parse(themeData)
            styleId = data.styleId
            color = data.color
            isHide = data.isHide
        }
        if(options){
            styleId = options.styleId
            color = options.color
            isHide = options.isHide
        }
        const defaultStyleData = styleList.find(item => item.id === styleId)
        const defaultColor = colorList.find(item => item.color === color) || {color}
        return {
            defaultStyleData,
            defaultColor,
            isHide
        }


    }

    static setTheme(data){
        localStorage.setItem(Theme.key, data)
    }
}
